<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/easyui_insdep_head :: easyui_insdep_head" th:with="title='配件标签管理'">
</head>
<body>
<div class="easyui-layout" style="width:100%;height:100%;overflow: hidden">
    <div data-options="region:'west',collapsible:false" style="width:33%;height:100%;overflow: hidden">
        <table id="component_tt" class="easyui-datagrid" style="width:100%;height:100%"
               url="/component/"  singleSelect="true" pagination="true" method="get"
                >
            <thead>
            <tr>
                <th field="compName" style="width:95%;">配件类型</th>
            </tr>
            </thead>
        </table>
        <script type="text/javascript">
            //<![CDATA[
            $(function () {
                $('#component_tt').datagrid({
                    onSelect: function(index, row){
                        $('#cp_tt').datagrid('load', {
                            compId : row.compId
                        });
                    }
                });
                var pager = $('#component_tt').datagrid().datagrid('getPager');	// get the pager of datagrid
                pager.pagination({
                    layout:['refresh']
                });
                pager.pagination({
                    buttons: [{
                        iconCls: 'icon-add',
                        handler: function () {
                            $.messager.prompt('增加类型', '请输入类型名称', function(r){
                                if (r){
                                    $.post("/component/", {compName: r}, function (data) {
                                        var data = data == "success" ? "添加成功" : "添加失败";
                                        $.messager.alert('结果', data, 'info');
                                        $("#component_tt").datagrid("reload");
                                    });
                                }
                            });
                        }
                    }, {
                        iconCls: 'icon-edit',
                        handler: function () {
                            row = $("#component_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请选中需要修改的类型', 'info');
                                return;
                            }

                            $.messager.prompt('修改类型', '请输入新的类型名称', function(r){
                                if (r){
                                    $.ajax({
                                        url: "/component/",
                                        type: "PUT",
                                        data: {
                                            compId : row.compId,
                                            compName : r
                                        },
                                        success: function (data) {
                                            var data = data == "success" ? "修改成功" : "修改失败";
                                            $.messager.alert('结果', data, 'info');
                                            $("#component_tt").datagrid("reload");
                                        }
                                    });
                                }
                            });
                        }
                    }, {
                        iconCls: 'icon-remove',
                        handler: function () {
                            row = $("#component_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请选中需要删除的类型', 'info');
                                return;
                            }

                            $.messager.confirm('警告', '确定删除该类型吗', function (r) {
                                if (r) {
                                    $.ajax({
                                        url: "/component/" + row.compId,
                                        type: "DELETE",
                                        success: function (data) {
                                            var data = data == "success" ? "删除成功" : "删除失败";
                                            $.messager.alert('结果', data, 'info');
                                            $("#component_tt").datagrid("reload");
                                        }
                                    });
                                }
                            });
                        }
                    }]
                });


            });
            //]]>
        </script>
    </div>

    <div data-options="region:'center'" style="height:100%;overflow: hidden">
        <table id="cp_tt" class="easyui-datagrid" style="width:100%;height:100%"
               url="/componentParameter/"  singleSelect="true" pagination="true" method="get"
        >
            <thead>
            <tr>
                <th field="compParamName" style="width:95%;">配件属性</th>
            </tr>
            </thead>
        </table>
        <script type="text/javascript">
            //<![CDATA[
            $(function () {
                $('#cp_tt').datagrid({
                    onSelect: function(index, row){
                        $('#cpd_tt').datagrid('load', {
                            compParamId : row.compParamId
                        });
                    }
                });
                var pager = $('#cp_tt').datagrid().datagrid('getPager');	// get the pager of datagrid
                pager.pagination({
                    layout:['refresh']
                });
                pager.pagination({
                    buttons: [{
                        iconCls: 'icon-add',
                        handler: function () {
                            row = $("#component_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请于左边表格中选中需要增加属性的配件类型', 'info');
                                return;
                            }

                            $.messager.prompt('增加属性', '请输入属性名称', function(r){
                                if (r){
                                    $.post("/componentParameter/", {
                                        compId : row.compId,
                                        compParamName: r
                                    }, function (data) {
                                        var data = data == "success" ? "添加成功" : "添加失败";
                                        $.messager.alert('结果', data, 'info');
                                        $("#cp_tt").datagrid("reload");
                                    });
                                }
                            });
                        }
                    }, {
                        iconCls: 'icon-edit',
                        handler: function () {
                            row = $("#cp_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请选中需要修改的属性', 'info');
                                return;
                            }

                            $.messager.prompt('修改类型', '请输入新的属性名称', function(r){
                                if (r){
                                    $.ajax({
                                        url: "/componentParameter/",
                                        type: "PUT",
                                        data: {
                                            compParamId : row.compParamId,
                                            compParamName : r
                                        },
                                        success: function (data) {
                                            var data = data == "success" ? "修改成功" : "修改失败";
                                            $.messager.alert('结果', data, 'info');
                                            $("#cp_tt").datagrid("reload");
                                        }
                                    });
                                }
                            });
                        }
                    }, {
                        iconCls: 'icon-remove',
                        handler: function () {
                            row = $("#cp_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请选中需要删除的属性', 'info');
                                return;
                            }

                            $.messager.confirm('警告', '确定删除该属性吗', function (r) {
                                if (r) {
                                    $.ajax({
                                        url: "/componentParameter/" + row.compParamId,
                                        type: "DELETE",
                                        success: function (data) {
                                            var data = data == "success" ? "删除成功" : "删除失败";
                                            $.messager.alert('结果', data, 'info');
                                            $("#cp_tt").datagrid("reload");
                                        }
                                    });
                                }
                            });
                        }
                    }]
                });


            });
            //]]>
        </script>
    </div>


    <div data-options="region:'east',collapsible:false" style="width:33%;height:100%;overflow: hidden">
        <table id="cpd_tt" class="easyui-datagrid" style="width:100%;height:100%"
               url="/componentParameterDetail/"  singleSelect="true" pagination="true" method="get"
        >
            <thead>
            <tr>
                <th field="compParamDetName" style="width:95%;">参数属性</th>
            </tr>
            </thead>
        </table>
        <script type="text/javascript">
            //<![CDATA[
            $(function () {
                var pager = $('#cpd_tt').datagrid().datagrid('getPager');	// get the pager of datagrid
                pager.pagination({
                    layout:['refresh']
                });
                pager.pagination({
                    buttons: [{
                        iconCls: 'icon-add',
                        handler: function () {
                            row = $("#cp_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请于左边表格中选中需要增加参数的属性类型', 'info');
                                return;
                            }

                            $.messager.prompt('增加参数', '请输入参数名称', function(r){
                                if (r){
                                    $.post("/componentParameterDetail/", {
                                        compParamId : row.compParamId,
                                        compParamDetName : r
                                    }, function (data) {
                                        var data = data == "success" ? "添加成功" : "添加失败";
                                        $.messager.alert('结果', data, 'info');
                                        $("#cpd_tt").datagrid("reload");
                                    });
                                }
                            });
                        }
                    }, {
                        iconCls: 'icon-edit',
                        handler: function () {
                            row = $("#cpd_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请选中需要修改的参数', 'info');
                                return;
                            }

                            $.messager.prompt('修改参数', '请输入新的参数名称', function(r){
                                if (r){
                                    $.ajax({
                                        url: "/componentParameterDetail/",
                                        type: "PUT",
                                        data: {
                                            compParamDetId : row.compParamDetId,
                                            compParamDetName : r
                                        },
                                        success: function (data) {
                                            var data = data == "success" ? "修改成功" : "修改失败";
                                            $.messager.alert('结果', data, 'info');
                                            $("#cpd_tt").datagrid("reload");
                                        }
                                    });
                                }
                            });
                        }
                    }, {
                        iconCls: 'icon-remove',
                        handler: function () {
                            row = $("#cpd_tt").datagrid('getSelected');

                            if (row == null) {
                                $.messager.alert('警告', '请选中需要删除的参数', 'info');
                                return;
                            }

                            $.messager.confirm('警告', '确定删除该参数吗', function (r) {
                                if (r) {
                                    $.ajax({
                                        url: "/componentParameterDetail/" + row.compParamDetId,
                                        type: "DELETE",
                                        success: function (data) {
                                            var data = data == "success" ? "删除成功" : "删除失败";
                                            $.messager.alert('结果', data, 'info');
                                            $("#cpd_tt").datagrid("reload");
                                        }
                                    });
                                }
                            });
                        }
                    }]
                });
            });
            //]]>
        </script>
    </div>


</div>
</body>


</html>